#include <stdio.h>
#include <stdlib.h>

typedef struct note {
	int data;
	struct note * next;
}Elem;

Elem *CreateCyclicLink(int a[],int n){
	Elem *p,*h=NULL,*t;
	int i;
	for (i=0;i<n;i++){
		p= (Elem *) malloc (sizeof (Elem));
		p->data=a[i];
		if (!h){
			p->next=p;
			h=t=p;
		}
		else {
			p->next=h;
			t=t->next=p;
		}
	}
	return h;
} 

void PrintLink(Elem *h){
	Elem *p;
	do{
		printf("%5d",p->data);
		p=p->next;
	}while (p!=h);
}

Elem * DelKey(Elem *h,int key){
	Elem *p,*q;
	for (q=h,p=h->next;p-h;q=p,p=p->next)
		if (p->data==key){
			q->next=p->next;
			free(p);
		}
	if (p->data==key){
		q->next=p->next;
		free(p);
		h=q;
	}
	return h;	
}

int main(void){
	Elem *head;
	int a[10]={7,68,7,3,1,5,5,8,5,5};
	head=CreateCyclicLink(a,10);
	head=DelKey(head,7);
	PrintLink(head);
}
